﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfWordsLearner.Helper;
using System.Windows.Input;
using System.Windows;

namespace WpfWordsLearner.ViewModels
{
	public class TestSettingViewModel : BaseViewModel
	{
		private Model.TestSettingsModel m_testSettings = null;

		public TestSettingViewModel()
		{
			m_testSettings = new Model.TestSettingsModel();
			m_testSettings.WordsCount = 10;
		}

		public Model.TestSettingsModel TestSettings
		{
			get { return m_testSettings; }
			set
			{
				m_testSettings = value;
				OnPropertyChanged(() => TestSettings);
			}
		}

		public ICommand ProceedCommand { get { return new BaseCommand(Proceed); } }
		private void Proceed()
		{
			Cancel();
			Views.TestView testWindow = new Views.TestView();
			ViewModels.TestViewModel testVM = testWindow.MainLayout.DataContext as ViewModels.TestViewModel;
			testVM.SetTestSettings(m_testSettings);
			testWindow.Show();
			testWindow.Owner = App.Current.MainWindow;
		}

		public ICommand CancelCommand { get { return new BaseCommand(Cancel); } }
		private void Cancel()
		{
			Window wind = App.Current.Windows.Cast<Window>().FirstOrDefault(window => window.IsActive);
			if (wind != null)
			{
				wind.Close();
			}
		}

	}
}
